package com.aliyun.flashsale.portal.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * 异常 utils
 *
 * 
 * @date 2024/12/01
 */
public abstract class ExceptionUtils {

    /**
     * 获取根消息
     *
     * @param throwable
     * @return {@link String }
     */
    public static String getRootCauseMessage(Throwable throwable, String defaultMessage) {
        Throwable rootCause = org.apache.commons.lang3.exception.ExceptionUtils.getRootCause(throwable);
        String message = rootCause == null ? throwable.getMessage() : rootCause.getMessage();
        return StringUtils.defaultIfBlank(message, defaultMessage);
    }
}
